var prefix = jsctx + "/hlhtTenantOpenList";

var updateOrder = (function () {
    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        window.history.back();
    }


    function save() {


        var outOrderNumList = [];
        $("#frmReUpdateOrder input").each(function () {
            var obj =  $(this).val();
            if(obj != '' && obj != null){
                outOrderNumList.push(obj);
            }
        });

        var outOrderNum = $("#outOrderNum").val();
        var outOrderNumList = outOrderNum.split(/[\n]/);
        outOrderNumList.forEach(function(item, index, arr) {
            if(item == "") {
                arr.splice(index, 1);
            }
        });

        if (outOrderNumList.length > 10){
            return parent.layer.alert("订单号数量大于10");
        }



        $.ajax({
            cache: false,
            type: "POST",
            url: prefix + "/reUpdateOrder",
            data:JSON.stringify(outOrderNumList),
            dataType: "json",
            headers:{
                'Content-Type':'application/json;charset=UTF-8',
            },
            beforeSend: function () {
                isajaxsend = false
            },
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.status == 200) {
                    parent.layer.msg("操作成功");
                    window.history.back();
                } else {
                    parent.layer.alert(data.message)
                }
            },
            complete: function () {
                isajaxsend = false
            }
        });
    }


    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    return {
        goBack: goBack,
        reLoad: reLoad,
        save:save

    };
})();






